<template>
  <div class="cart-list-item">
    <check-button class="check-button" :checked="goods.checked" @click.native="checkedClick"/>
    <div class="goods-item">
      <div class="goods-img">
        <img :src='goods.image'>
      </div>
      <div class="goods-desc">
        <p class="title">{{goods.title}}</p>
        <div class="goods-price">
          <span class="price">{{goods.price | formatPrice}}</span>
          <div class="goods-count">
            <span class="calc" @click="incClick">+</span>
            <span class="count">{{goods.count}}</span>
            <span class="calc" @click="decClick">-</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import CheckButton from 'components/content/checkButtom/CheckButton'

  export default {
    name: "CartListItem",
    components: {CheckButton},
    props: {
      goods: {
        type: Object,
        default: {}
      }
    },
    methods: {
      checkedClick() {
        this.$emit('checkedClick')
      },
      incClick() {
        this.$emit('incClick')
      },
      decClick() {
        if (this.goods.count > 1) {
          this.$emit('decClick')
        }
      }
    }
  }
</script>

<style scoped>
  .cart-list-item {
    border: 2px solid #f2f5f8;
    border-radius: 10px;
    min-height: 110px;
    padding: 10px;
    margin: 10px;
  }

  .check-button {
    float: left;
    position: relative;
    top: 45px;
    margin-right: 10px;
  }


  .goods-item {
    display: flex;
    flex-flow: wrap;
  }

  .goods-img {
    max-height: 110px;
    overflow: hidden;
    width: 20%;
  }

  .goods-img img{
    width: 100%;
  }

  .goods-desc {
    padding-left: 15px;
    width: 80%;
    font-size: 14px;
  }

  .goods-price {
    margin-top: 30px;
  }

  .price {
    color: var(--color-high-text);
    font-size: 18px;
  }

  .goods-count {
    float:right;
  }

  .goods-count span {
    float:right;
    display: block;
    text-align: center;
    color: #dadde0;
  }

  .calc {
    width: 20px;
    border: 1px solid #dadde0;
  }

  .count {
    width: 35px;
    border-top: 1px solid #dadde0;
    border-bottom: 1px solid #dadde0;
  }

</style>